package com.gisocn.onemap.ui.alert;

import android.app.Dialog;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import androidx.fragment.app.MvpDialogFragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.esri.android.map.Layer;
import com.gisocn.onemap.databinding.AlertColumnSelectedBinding;
import com.gisocn.onemap.interfaces.OnSingleItemClickListener;
import com.gisocn.onemap.model.FieldDataBean;
import com.gisocn.onemap.mvp.contact.ColumnSelectedContact;
import com.gisocn.onemap.mvp.presenter.ColumnSelectedPresenter;
import com.gisocn.onemap.sgzx.R;
import com.gisocn.onemap.ui.adapter.ColumnSelectedAdapter;
import com.google.android.material.badge.BadgeDrawable;
import java.util.ArrayList;
import java.util.List;

/* loaded from: classes2.dex */
public class AlertColumnSelected extends MvpDialogFragment<AlertColumnSelectedBinding, ColumnSelectedContact.Presenter> implements ColumnSelectedContact.View {
    private View anchorView;
    private ColumnSelectedAdapter columnSelectedAdapter;
    private final List<FieldDataBean> fieldDataList = new ArrayList();
    private OnColumnSelectCallback onColumnSelectCallback;
    private Layer selectLayer;
    private String showLayersData;
    private String tableName;

    /* loaded from: classes2.dex */
    public interface OnColumnSelectCallback {
        void selectCallback(FieldDataBean fieldDataBean);
    }

    @Override // androidx.fragment.app.BaseDialogFragment
    protected void dismissEvent() {
    }

    @Override // androidx.fragment.app.BaseDialogFragment
    protected int getLayoutId() {
        return R.layout.alert_column_selected;
    }

    @Override // androidx.fragment.app.BaseDialogFragment
    protected void initListener() {
    }

    @Override // androidx.fragment.app.BaseDialogFragment
    protected boolean isBottomDialog() {
        return false;
    }

    @Override // androidx.fragment.app.BaseDialogFragment
    protected boolean isTopDialog() {
        return false;
    }

    @Override // androidx.fragment.app.BaseDialogFragment
    protected boolean isTranslucentDialog() {
        return false;
    }

    @Override // androidx.fragment.app.BaseDialogFragment
    protected void initView() {
        if (this.columnSelectedAdapter == null) {
            ((AlertColumnSelectedBinding) this.mViewDataBinding).rvColumnData.setLayoutManager(new LinearLayoutManager(this.context));
            this.columnSelectedAdapter = new ColumnSelectedAdapter(R.layout.item_column_select, this.fieldDataList);
            ((AlertColumnSelectedBinding) this.mViewDataBinding).rvColumnData.setAdapter(this.columnSelectedAdapter);
            this.columnSelectedAdapter.setOnItemClickListener(new OnSingleItemClickListener() { // from class: com.gisocn.onemap.ui.alert.AlertColumnSelected.1
                @Override // com.gisocn.onemap.interfaces.OnSingleItemClickListener
                protected void onSingleItemClick(BaseQuickAdapter<?, ?> baseQuickAdapter, View view, int i) {
                    if (i >= AlertColumnSelected.this.fieldDataList.size()) {
                        return;
                    }
                    AlertColumnSelected.this.dismiss();
                    FieldDataBean fieldDataBean = (FieldDataBean) AlertColumnSelected.this.fieldDataList.get(i);
                    if (AlertColumnSelected.this.onColumnSelectCallback != null) {
                        AlertColumnSelected.this.onColumnSelectCallback.selectCallback(fieldDataBean);
                    }
                }
            });
        }
        getColumnData();
    }

    private void getColumnData() {
        if (this.fieldDataList.size() > 0) {
            this.fieldDataList.clear();
        }
        showProgressDialog();
        String url = this.selectLayer.getUrl();
        if (TextUtils.isEmpty(url)) {
            return;
        }
        if (url.startsWith("http")) {
            getPresenter().getHttpColumnData(this.selectLayer, this.showLayersData);
        } else {
            getPresenter().getXmlColumnData(this.tableName);
        }
    }

    public AlertColumnSelected setAnchorView(View view) {
        this.anchorView = view;
        return this;
    }

    public AlertColumnSelected setSelectLayer(Layer layer) {
        this.selectLayer = layer;
        return this;
    }

    public AlertColumnSelected setShowLayersData(String str) {
        this.showLayersData = str;
        return this;
    }

    public AlertColumnSelected setTableName(String str) {
        this.tableName = str;
        return this;
    }

    public AlertColumnSelected setOnColumnSelectCallback(OnColumnSelectCallback onColumnSelectCallback) {
        this.onColumnSelectCallback = onColumnSelectCallback;
        return this;
    }

    @Override // androidx.fragment.app.Fragment
    public void onPause() {
        super.onPause();
    }

    @Override // androidx.fragment.app.Fragment
    public void onResume() {
        super.onResume();
        Dialog dialog = getDialog();
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        Window window = dialog.getWindow();
        View view = this.anchorView;
        if (view != null) {
            int[] iArr = new int[2];
            view.getLocationOnScreen(iArr);
            WindowManager.LayoutParams attributes = window.getAttributes();
            attributes.gravity = BadgeDrawable.TOP_START;
            attributes.x = iArr[0];
            attributes.y = (int) (iArr[1] + this.context.getResources().getDimension(R.dimen.dp_30));
            attributes.width = -2;
            attributes.height = -2;
            window.setAttributes(attributes);
        }
    }

    @Override // androidx.fragment.app.MvpDialogFragment
    public ColumnSelectedContact.Presenter createPresenter() {
        return new ColumnSelectedPresenter();
    }

    @Override // com.gisocn.onemap.mvp.contact.ColumnSelectedContact.View
    public void columnDataSuccess(List<FieldDataBean> list) {
        if (list != null && list.size() > 0) {
            this.fieldDataList.addAll(list);
        }
        this._mActivity.runOnUiThread(new Runnable() { // from class: com.gisocn.onemap.ui.alert.AlertColumnSelected.2
            @Override // java.lang.Runnable
            public void run() {
                AlertColumnSelected.this.closeLoadingDialog();
                ((AlertColumnSelectedBinding) AlertColumnSelected.this.mViewDataBinding).rvColumnData.setVisibility(AlertColumnSelected.this.fieldDataList.size() > 0 ? 0 : 4);
                ((AlertColumnSelectedBinding) AlertColumnSelected.this.mViewDataBinding).tvNoData.setVisibility(AlertColumnSelected.this.fieldDataList.size() > 0 ? 4 : 0);
                AlertColumnSelected.this.columnSelectedAdapter.notifyDataSetChanged();
            }
        });
    }
}
